<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="料号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemNo">
              <a-input v-model="model.itemNo" placeholder="请输入料号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产日期(长度6位)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manufactureDate">
              <a-input v-model="model.manufactureDate" placeholder="请输入生产日期(长度6位)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产批号（长度不超过8位）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lotNo">
              <a-input v-model="model.lotNo" placeholder="请输入生产批号（长度不超过8位）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="版本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="edition">
              <a-input v-model="model.edition" placeholder="请输入版本"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="外箱数量(Quantity最小包装的数量;外箱 Label 时代表整箱的数量)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outerBoxesNum">
              <a-input v-model="model.outerBoxesNum" placeholder="请输入外箱数量(Quantity最小包装的数量;外箱 Label 时代表整箱的数量)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模穴号（生产时的模穴号，没有则放0）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="moldCavityNo">
              <a-input v-model="model.moldCavityNo" placeholder="请输入模穴号（生产时的模穴号，没有则放0）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机种名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="modelName">
              <a-input v-model="model.modelName" placeholder="请输入机种名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productName">
              <a-input v-model="model.productName" placeholder="请输入品名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="包装日期(默认等于填的生产日期)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="packingDate">
              <a-input v-model="model.packingDate" placeholder="请输入包装日期(默认等于填的生产日期)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="材质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialTexture">
              <a-input v-model="model.materialTexture" placeholder="请输入材质"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="色号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="colorCode">
              <a-input v-model="model.colorCode" placeholder="请输入色号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否外箱（B外箱I内箱）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outerBox">
              <a-input v-model="model.outerBox" placeholder="请输入是否外箱（B外箱I内箱）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="箱号（条码总长18位）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reelId">
              <a-input v-model="model.reelId" placeholder="请输入箱号（条码总长18位）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="二维码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qrCode">
              <a-input v-model="model.qrCode" placeholder="请输入二维码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="AA1（vendorCode 光宝分配给供应商的代码，长度6位）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="aa1">
              <a-input v-model="model.aa1" placeholder="请输入AA1（vendorCode 光宝分配给供应商的代码，长度6位）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="AA2(reelId的前12位)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="aa2">
              <a-input v-model="model.aa2" placeholder="请输入AA2(reelId的前12位)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="流水号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serialNumber">
              <a-input v-model="model.serialNumber" placeholder="请输入流水号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="箱数(默认1)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="casesNum">
              <a-input v-model="model.casesNum" placeholder="请输入箱数(默认1)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="尾数数量(默认为0)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mantissaQuantity">
              <a-input v-model="model.mantissaQuantity" placeholder="请输入尾数数量(默认为0)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalNum">
              <a-input-number v-model="model.totalNum" placeholder="请输入总数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ChAssociationPrintHistoryForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/chAssociationPrintHistory/add",
          edit: "/ch/chAssociationPrintHistory/edit",
          queryById: "/ch/chAssociationPrintHistory/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>